package cn.tedu.ivos.application.controller;

import cn.tedu.ivos.application.pojo.dto.ApplicationQuery;
import cn.tedu.ivos.application.pojo.dto.ApplicationSaveParam;
import cn.tedu.ivos.application.service.ApplicationService;
import cn.tedu.ivos.base.response.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 */
@Slf4j
@RestController
@RequestMapping("/v1/application")
public class ApplicationController {
    @Autowired
    ApplicationService applicationService;

    @PostMapping("save")
    public JsonResult saveApplication(ApplicationSaveParam applicationSaveParam) {
        log.debug("保存申请单:applicationSaveParam={}", applicationSaveParam);
        applicationService.save(applicationSaveParam);
        return JsonResult.ok();
    }
    @GetMapping("select")
    public JsonResult selectApplication(ApplicationQuery applicationQuery) {
        log.debug("查询申请单:applicationQuery={}", applicationQuery);
        return JsonResult.ok(applicationService.selectApplication(applicationQuery));
    }
    @PostMapping("cancel/{applicationId}")
    public JsonResult cancelApplication(@PathVariable Long applicationId) {
        log.debug("取消申请单:applicationId={}", applicationId);
        applicationService.cancelApplication(applicationId);
        return JsonResult.ok();
    }
    @PostMapping("distribute/{applicationId}/{vehicleId}")
    public JsonResult distributionApplication(@PathVariable Long applicationId, @PathVariable Long vehicleId) {
        log.debug("分配申请单:applicationId={},vehicleId={}", applicationId, vehicleId);
        applicationService.distribute(applicationId, vehicleId);
        return JsonResult.ok();
    }
    @PostMapping("back/{applicationId}/{vehicleId}")
    public JsonResult back(
            @PathVariable Long applicationId, @PathVariable Long vehicleId) {
        log.debug("归还车辆:applicationId={},vehicleId={}", applicationId, vehicleId);
        applicationService.back(applicationId, vehicleId);
        return JsonResult.ok();
    }

}
